﻿@using Domain.Entity
@using Microsoft.Web.Helpers
@model Domain.Entity.Game


@{
    ViewBag.Title = @Model.Name;
    Layout = null;
}
<head>
    <script type="text/javascript">
        function Rate(rating) {
            document.getElementById('rating').value = rating;
            for (var i = 1; i <= 5; i++)
                if (i <= rating)
                    document.getElementById('star' + i).setAttribute('src', '../../GamersParadise/Images/yellowStar.png')
                else
                    document.getElementById('star' + i).setAttribute('src', '../../GamersParadise/Images/whiteStar.png')
        }

        function Rating() {
            var xmlhttp;
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    document.getElementById("userReview").innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET", "Rate?rating=" + document.getElementById("rating").value + "&gameId=" +
                document.getElementById("gameId").value, true);
            xmlhttp.send();
        } 
    </script>
    <title>@Model.Name</title>
</head>

    
<div id="titlelessItem">
    <div class="item">
        <h1 class="title @Html.GetColor(Request.Cookies["color"])">@Model.Name</h1>
        @ViewBag.Name

        <div class="descBox descBlack">@Model.Description</div>
        
        <div class="sideBox @Html.GetColor(Request.Cookies["color"])">
            @foreach(Platform p in Model.Platforms)
            {
                <img src="@Html.Action("GetImage", "Platform")"/>
            }
        </div>

        <br />
        <div id="userReview"></div>
        <div class="Rating sideBox @Html.GetColor(Request.Cookies["color"])" style="width: 502px;">
            <img id="star1" src="../../GamersParadise/Images/whiteStar.png" alt="Rating" height="42" width="50" onclick="Rate(1)"/>
            <img id="star2" src="../../GamersParadise/Images/whiteStar.png" alt="Rating" height="42" width="50" onclick="Rate(2)"/>
            <img id="star3" src="../../GamersParadise/Images/whiteStar.png" alt="Rating" height="42" width="50" onclick="Rate(3)"/>
            <img id="star4" src="../../GamersParadise/Images/whiteStar.png" alt="Rating" height="42" width="50" onclick="Rate(4)"/>
            <img id="star5" src="../../GamersParadise/Images/whiteStar.png" alt="Rating" height="42" width="50" onclick="Rate(5)"/><br/><br/><br/>
            <input id="rating" type="hidden" name="rating" />
            <input id="gameId" type="hidden" value="@Model.Id" />
            <input type="button" value="Rate"  onclick="Rating()" class="actionButtons @Html.GetColor(Request.Cookies["color"])"/>
        </div>
        <br/>
        <div class="sideBox @Html.GetColor(Request.Cookies["color"])" style="width: 295px;padding-bottom: 20px; font-weight: bold; margin-bottom: 5px;">
            <div style="float:left;">Year Released</div>
            <div style="float:right;">@Model.ReleaseDate.Month/@Model.ReleaseDate.Day/@Model.ReleaseDate.Year</div>
        </div>
        <div class="sideBox @Html.GetColor(Request.Cookies["color"])" style="width: 295px;padding-bottom: 20px; font-weight: bold; margin-bottom: 5px;">
            <div style="float:left;">Rating</div>
            <div style="float:right;">@string.Format("{0:0.0}",Model.AverageRating)/5</div>
        </div>

        @if (Model.MetaScores.Any())
        {
            <div class="sideBox @Html.GetColor(Request.Cookies["color"])" style="width: 295px;padding-bottom: 20px; font-weight: bold; margin-bottom: 5px;">
                <div style="float:left;">Meta Score</div>
                <div style="float:right;">@Model.MetaScores.Select(s => s.Score).Average()</div>
            </div>
        }
        <br/>

        @{
            Pro260Website.Models.VideoViewModel viewModel = new Pro260Website.Models.VideoViewModel()
                                                                {
                                                                    YoutubeID = Model.YoutubeLink,
                                                                    VideoName = Model.FileName
                                                                };

            Html.RenderPartial("VideoDisplay", viewModel);        
        }
    
        <br/>

        @if (Model.SystemRequirements != null)
        {
            <h2 class="title @Html.GetColor(Request.Cookies["color"])">System Requirements</h2>
            <p class="descBackground" id="systemRequirements">
                <em>OS:</em> @Model.SystemRequirements.OS     <br />
                <em>Video Card:</em> @Model.SystemRequirements.VideoCard    <br />
                <em>Processor:</em> @Model.SystemRequirements.Processor    <br />
                <em>Memory:</em> @Model.SystemRequirements.Memory
            </p>
        }
        <br/>

        <div style="padding: 15px; width: 94.5%;" class="sideBox coolBlack"> 
                @if(User.Identity.Name != "")
                {
                    @Html.ActionLink("Create Review", "CreateReview", "Review", new { gameId = Model.Id }, new { @class = "actionButtons " + @Html.GetColor(Request.Cookies["color"]) })
                }

                @if (Model.Articles.Any())
                {
                    @Html.ActionLink("News", "ViewGameNews", "News", new { gameId = Model.Id }, new { @class = "actionButtons " + @Html.GetColor(Request.Cookies["color"]) })
                }
            @using (Html.BeginForm("AmazonSearch", "Search"))
            {
                <input type="hidden" name="searchItem" value="@Model.Name" />
                <input type="submit" value="Search Amazon" class="actionButtons @Html.GetColor(Request.Cookies["color"])"/>
            }
            @using (Html.BeginForm("GamestopSearch", "Search"))
            {
                <input type="hidden" name="searchItem" value="@Model.Name" />
                <input type="submit" value="Search Gamestop" class="actionButtons @Html.GetColor(Request.Cookies["color"])"/>
            }
            @using (Html.BeginForm("GoogleShoppingSearch", "Search"))
            {
                <input type="hidden" name="searchItem" value="@Model.Name" />
                <input type="submit" value="Search Google Shopping" class="actionButtons @Html.GetColor(Request.Cookies["color"])"/>
            }
        </div>
        
        <br/>
                 <div style="background-color: rgb(226, 230, 245);border: 2px solid #627AAD;border-radius:1.2em;padding: 10px 0 0 0">
            @Facebook.LikeButton("", "standard", true, 200, 70)
        </div>    


    </div>
</div>
